<?php

class OrganizationsList extends OrganizationsAbstractList
{

    function __construct()
    {
        parent::__construct( 'organization', 50, '',
                array( 'fiscal_id' => 1, 'name' => 1, 'commercial_name' => 1, 'atime' => 1 ) );
    }

    function crear()
    {
        //me falta el logo y el
        $sql = 'INSERT INTO enterprises ( resource, name, fiscal_id, commercial_name, logo, css ) VALUES (\'R_ORG\',' . MyLink::quote( $_POST[ 'name' ] ) . ',' . MyLink::quote( $_POST[ 'fiscal_id' ] ) . ',' . MyLink::quote( $_POST[ 'commercial_name' ] ) . ',\'' . $this->extension . '\',\'' . ( (empty( $_FILES[ 'css' ] ) || empty( $_FILES[ 'css' ][ 'tmp_name' ] )) ? 'N' : 'S') . '\')';
        MyLink::$default->execute( $sql );
        $insertId = MyLink::$default->insert_id;

        if ( !empty( $this->extension ) )
                move_uploaded_file( $_FILES[ 'logo' ][ 'tmp_name' ],
                    'archivos' . DIRECTORY_SEPARATOR . 'logos' . DIRECTORY_SEPARATOR . $insertId . '.' . $this->extension );

        if ( !empty( $_FILES[ 'css' ] ) )
                move_uploaded_file( $_FILES[ 'logo' ][ 'tmp_name' ],
                    'archivos' . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . $insertId . '.css' );


        Security::addRolEdges( array( 'SUPERADMIN' => array( 0 ) ), 'ADM_ORG',
                $insertId );

        Security::addPrivilege( 'ADM_ORG', $insertId, 'R_USR_ORG', $insertId,
                'UserOrganization' );
        Security::addPrivilege( 'ADM_ORG', $insertId, 'R_ADM_ORG', $insertId,
                'UserAdminOrganization' );

        Security::addPrivilege( 'SUPERADMIN', 0, 'R_ORG', $insertId,
                'Organization' );

        //MyLink::$default->end(false);
    }

}

?>
